<template>
	<view>
		<simple-toolbar :title="$t('pool.editAwardPool.newAssetPool')">
			<view class="returnToConfirm">
				<el-button @click="navBack">{{ $t('pool.editAwardPool.return') }}</el-button>
				<el-button @click="confirm" type="primary" :disabled="success">{{ $t('pool.editAwardPool.confirm') }}</el-button>
			</view>
		</simple-toolbar>

		<view class="pad-base form">
			<el-form :model="formData" :rules="rules" ref="formData" label-position="top">
				<!-- <el-form-item :label="$t('pool.editAwardPool.public_key')" prop="public_key">
					<el-input v-model="formData.public_key" :placeholder="$t('pool.editAwardPool.public_key_pla')"></el-input>
				</el-form-item>
				<el-form-item :label="$t('pool.editAwardPool.wallet')" prop="wallet">
					<el-input v-model="formData.wallet" :placeholder="$t('pool.editAwardPool.wallet_pla')"></el-input>
				</el-form-item>
				<el-form-item :label="$t('pool.editAwardPool.current_tib')" prop="current_tib">
					<el-input v-model="formData.current_tib" :placeholder="$t('pool.editAwardPool.current_tib_pla')"></el-input>
				</el-form-item> -->
				<!-- <el-form-item :label="$t('pool.editAwardPool.balance')" prop="balance">
					<el-input v-model="formData.balance" :placeholder="$t('pool.editAwardPool.balance_pla')"></el-input>
				</el-form-item> -->
				<el-form-item :label="$t('wallet.editWallet.coin')" prop="coin">
					<el-select v-model="formData.coin" :placeholder="$t('wallet.editWallet.coin_pla')">
						<el-option v-for="item in coinList" :key="item.id" :label="item.coin_name" :value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item :label="$t('pool.editAwardPool.rewards')" prop="rewards">
					<el-input v-model="formData.rewards" :placeholder="$t('pool.editAwardPool.rewards_pla')"></el-input>
				</el-form-item>
				<!-- <el-form-item :label="$t('pool.editAwardPool.total_rewards')" prop="total_rewards">
					<el-input v-model="formData.total_rewards" :placeholder="$t('pool.editAwardPool.total_rewards_pla')"></el-input>
				</el-form-item> -->
			</el-form>
		</view>
	</view>
</template>

<script>
	import {
		assetPool
	} from "../../../js_sdk/uni-admin/assetPool.js"
	import {
		getCoinList
	} from "@/js_sdk/uni-admin/wallet.js"
	export default {
		onLoad(option) {
			this.state = option.state
			if (this.state == 1) return
			let data = JSON.parse(decodeURIComponent(option.data));
			this.formData = data.balance
		},
		data() {
			return {
				coinList: [],
				success: false,
				formData: {
					// public_key: '',
					// wallet: '',
					// current_tib: '',
					// balance: '',
					coin: '',
					rewards: '',
					pool: 1,
					// total_rewards: '',
				},
				rules: {
					// public_key: [{
					// 	required: true,
					// 	// message: '请输入公钥',
					// 	validator: (rule, value, callback) => {
					// 		if (value === '') {
					// 			callback(new Error(this.$t('pool.editAwardPool.public_key_pla')))
					// 		} else {
					// 			callback()
					// 		}
					// 	},
					// 	trigger: 'blur'
					// }],
					// wallet: [{
					// 	required: true,
					// 	// message: '请输入钱包地址',
					// 	validator: (rule, value, callback) => {
					// 		if (value === '') {
					// 			callback(new Error(this.$t('pool.editAwardPool.wallet_pla')))
					// 		} else {
					// 			callback()
					// 		}
					// 	},
					// 	trigger: 'blur'
					// }],
					// current_tib: [{
					// 	required: true,
					// 	// message: '请输入当前算力',
					// 	validator: (rule, value, callback) => {
					// 		if (value === '') {
					// 			callback(new Error(this.$t('pool.editAwardPool.current_tib_pla')))
					// 		} else {
					// 			callback()
					// 		}
					// 	},
					// 	trigger: 'blur'
					// }],
					// balance: [{
					// 	required: true,
					// 	// message: '请输入数量',
					// 	validator: (rule, value, callback) => {
					// 		if (value === '') {
					// 			callback(new Error(this.$t('pool.editAwardPool.balance_pla')))
					// 		} else {
					// 			callback()
					// 		}
					// 	},
					// 	trigger: 'blur'
					// }],
					coin: [{
						required: true,
						validator: (rule, value, callback) => {
							if (value === '') {
								callback(new Error(this.$t('wallet.editWallet.coin_pla')))
							} else {
								callback()
							}
						},
						trigger: 'blur'
					}],
					rewards: [{
						required: true,
						// message: '请输入挖矿收益',
						validator: (rule, value, callback) => {
							if (value === '') {
								callback(new Error(this.$t('pool.editAwardPool.rewards_pla')))
							} else {
								callback()
							}
						},
						trigger: 'blur'
					}],
					// total_rewards: [{
					// 	required: true,
					// 	// message: '请输入历史总挖矿量',
					// 	validator: (rule, value, callback) => {
					// 		if (value === '') {
					// 			callback(new Error(this.$t('pool.editAwardPool.total_rewards_pla')))
					// 		} else {
					// 			callback()
					// 		}
					// 	},
					// 	trigger: 'blur'
					// }],
				}
			}
		},
		async onShow() {
			// this.coinList = uni.getStorageSync('coinList')
			this.loadData()
		},
		methods: {
			async loadData() {
				try{
					let res = await getCoinList()
					this.coinList = res.data
				}catch(e){
					console.error(e)
				}
			},
			confirm() {
				this.$refs.formData.validate(async valid => {
					if (!valid) return
					let data = Object.assign({}, this.formData)
					data.rewards = parseFloat(data.rewards)
					if (this.state == 1) {
						// this.formData.current_tib = this.formData.current_tib * 1
						// this.formData.rewards = this.formData.rewards * 1
						// this.formData.distributed = true
						await assetPool('post', data)
					} else {
						
					}
					this.success = true
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				});
			},
			navBack() {
				uni.navigateBack()
			}
		},
	}
</script>

<style scoped>
	/deep/ .el-select {
		width: 100%;
	}
</style>